<?php
App::uses('AppController', 'Controller');

class ProductsController extends AppController {

	public $uses = array();
        function beforeFilter() {
            parent::beforeFilter();
            $AppInformation['Controller']['nameSingular'] = "cliente";
            $AppInformation['Controller']['namePlural'] = "clientes";
            $this->set("AppInformation",$AppInformation);
        }
        
        function admin_index()
        {
            $this->layout = "admin";
            $Products = $this->Product->find("all");
            
            $this->set('Products',$Products);
        }
        function admin_add()
        {
            $this->layout = "admin";
            
            if ($this->request->is('post'))
            {
//                die(debug($this->request->data));
                $this->Product->save($this->request->data);
                $this->Session->setFlash("Salvo com sucesso!");
                
                // Trocar 2 por getInsertLastInsert
                $this->redirect(array('action'=>'edit',2));
            }
        }
        function admin_edit($id=null)
        {
            $this->layout = "admin";
            
            if ($this->request->is('post'))
            {
//                die(debug($this->request->data));
                $this->Product->save($this->request->data);
                $this->Session->setFlash(__('Salvo com sucesso!'), 'Flashs/FlashMessengeGood');
            }
            else
            {
                $this->data = $this->Product->find("first", array("recursive"=>2,"conditions"=>array("id"=>$id)));
            }
        }
        
        function admin_delete($id)
        {
            $this->Product->delete($id);
            $this->Session->setFlash('Removido com sucesso.', 'default', array(), 'good');
            $this->redirect('/admin/pages');
        }
}
